from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-03 14:12:48.666224
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 03, Sep, 2021
Time: 14:12:52
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.9591
Nobs: 403.000 HQIC: -46.4986
Log likelihood: 4384.22 FPE: 4.49160e-21
AIC: -46.8522 Det(Omega_mle): 3.60243e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.429673 0.094378 4.553 0.000
L1.Burgenland 0.104146 0.048662 2.140 0.032
L1.Kärnten -0.115096 0.024219 -4.752 0.000
L1.Niederösterreich 0.167092 0.105011 1.591 0.112
L1.Oberösterreich 0.126555 0.102517 1.234 0.217
L1.Salzburg 0.281924 0.051090 5.518 0.000
L1.Steiermark 0.023350 0.067665 0.345 0.730
L1.Tirol 0.110026 0.053485 2.057 0.040
L1.Vorarlberg -0.113977 0.048166 -2.366 0.018
L1.Wien -0.006447 0.093110 -0.069 0.945
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.009270 0.219008 0.042 0.966
L1.Burgenland -0.045540 0.112922 -0.403 0.687
L1.Kärnten 0.037232 0.056202 0.662 0.508
L1.Niederösterreich -0.194223 0.243683 -0.797 0.425
L1.Oberösterreich 0.491571 0.237897 2.066 0.039
L1.Salzburg 0.305959 0.118556 2.581 0.010
L1.Steiermark 0.107358 0.157021 0.684 0.494
L1.Tirol 0.316292 0.124114 2.548 0.011
L1.Vorarlberg -0.004780 0.111771 -0.043 0.966
L1.Wien -0.011454 0.216066 -0.053 0.958
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.255102 0.047959 5.319 0.000
L1.Burgenland 0.088886 0.024728 3.595 0.000
L1.Kärnten -0.003001 0.012307 -0.244 0.807
L1.Niederösterreich 0.206924 0.053363 3.878 0.000
L1.Oberösterreich 0.169767 0.052096 3.259 0.001
L1.Salzburg 0.035553 0.025962 1.369 0.171
L1.Steiermark 0.017821 0.034385 0.518 0.604
L1.Tirol 0.063890 0.027179 2.351 0.019
L1.Vorarlberg 0.059206 0.024476 2.419 0.016
L1.Wien 0.107176 0.047315 2.265 0.024
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180661 0.046898 3.852 0.000
L1.Burgenland 0.047544 0.024181 1.966 0.049
L1.Kärnten -0.007327 0.012035 -0.609 0.543
L1.Niederösterreich 0.135974 0.052182 2.606 0.009
L1.Oberösterreich 0.319385 0.050943 6.269 0.000
L1.Salzburg 0.098517 0.025387 3.881 0.000
L1.Steiermark 0.133269 0.033624 3.963 0.000
L1.Tirol 0.076861 0.026578 2.892 0.004
L1.Vorarlberg 0.055278 0.023934 2.310 0.021
L1.Wien -0.040588 0.046268 -0.877 0.380
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208761 0.093507 2.233 0.026
L1.Burgenland -0.057059 0.048213 -1.183 0.237
L1.Kärnten -0.034927 0.023996 -1.456 0.146
L1.Niederösterreich 0.113533 0.104042 1.091 0.275
L1.Oberösterreich 0.168820 0.101572 1.662 0.096
L1.Salzburg 0.256564 0.050618 5.069 0.000
L1.Steiermark 0.082594 0.067041 1.232 0.218
L1.Tirol 0.122540 0.052991 2.312 0.021
L1.Vorarlberg 0.115428 0.047721 2.419 0.016
L1.Wien 0.028129 0.092251 0.305 0.760
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.026760 0.072647 0.368 0.713
L1.Burgenland 0.025116 0.037457 0.671 0.503
L1.Kärnten 0.051893 0.018642 2.784 0.005
L1.Niederösterreich 0.210378 0.080831 2.603 0.009
L1.Oberösterreich 0.338004 0.078912 4.283 0.000
L1.Salzburg 0.045425 0.039326 1.155 0.248
L1.Steiermark -0.003563 0.052085 -0.068 0.945
L1.Tirol 0.113853 0.041170 2.765 0.006
L1.Vorarlberg 0.063339 0.037075 1.708 0.088
L1.Wien 0.129701 0.071671 1.810 0.070
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185815 0.088448 2.101 0.036
L1.Burgenland 0.019611 0.045605 0.430 0.667
L1.Kärnten -0.059354 0.022698 -2.615 0.009
L1.Niederösterreich -0.124414 0.098414 -1.264 0.206
L1.Oberösterreich 0.198681 0.096077 2.068 0.039
L1.Salzburg 0.026566 0.047880 0.555 0.579
L1.Steiermark 0.300836 0.063414 4.744 0.000
L1.Tirol 0.490657 0.050125 9.789 0.000
L1.Vorarlberg 0.068547 0.045140 1.519 0.129
L1.Wien -0.104013 0.087260 -1.192 0.233
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158614 0.096453 1.644 0.100
L1.Burgenland -0.006959 0.049732 -0.140 0.889
L1.Kärnten 0.062831 0.024752 2.538 0.011
L1.Niederösterreich 0.203435 0.107320 1.896 0.058
L1.Oberösterreich -0.126185 0.104771 -1.204 0.228
L1.Salzburg 0.241138 0.052213 4.618 0.000
L1.Steiermark 0.152201 0.069153 2.201 0.028
L1.Tirol 0.051923 0.054661 0.950 0.342
L1.Vorarlberg 0.123121 0.049225 2.501 0.012
L1.Wien 0.142930 0.095157 1.502 0.133
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488118 0.052251 9.342 0.000
L1.Burgenland -0.010713 0.026941 -0.398 0.691
L1.Kärnten -0.010587 0.013409 -0.790 0.430
L1.Niederösterreich 0.205276 0.058138 3.531 0.000
L1.Oberösterreich 0.256568 0.056757 4.520 0.000
L1.Salzburg 0.022652 0.028285 0.801 0.423
L1.Steiermark -0.023606 0.037462 -0.630 0.529
L1.Tirol 0.070587 0.029611 2.384 0.017
L1.Vorarlberg 0.058383 0.026666 2.189 0.029
L1.Wien -0.053745 0.051549 -1.043 0.297
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.018990 0.076904 0.134099 0.134432 0.040472 0.068555 0.001033 0.174879
Kärnten 0.018990 1.000000 -0.045940 0.125919 0.047122 0.069256 0.456353 -0.093540 0.091915
Niederösterreich 0.076904 -0.045940 1.000000 0.283590 0.085065 0.270995 0.020653 0.147580 0.252757
Oberösterreich 0.134099 0.125919 0.283590 1.000000 0.182635 0.287864 0.152895 0.108573 0.135417
Salzburg 0.134432 0.047122 0.085065 0.182635 1.000000 0.128499 0.056810 0.103838 0.050976
Steiermark 0.040472 0.069256 0.270995 0.287864 0.128499 1.000000 0.130485 0.087898 -0.026602
Tirol 0.068555 0.456353 0.020653 0.152895 0.056810 0.130485 1.000000 0.042306 0.117099
Vorarlberg 0.001033 -0.093540 0.147580 0.108573 0.103838 0.087898 0.042306 1.000000 -0.045155
Wien 0.174879 0.091915 0.252757 0.135417 0.050976 -0.026602 0.117099 -0.045155 1.000000